package com.htfyun.eink.pw.draw;

import android.graphics.Paint;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.htfyun.eink.pw.configs.ConfigPen;

import java.util.Objects;

public class PWPaintConfig {

    public float strokeWidth = ConfigPen.WRITER_STROKE_WIDTH_DEFAULT;
    @ColorInt
    public int color = ConfigPen.WRITER_COLOR_DEFAULT;

    public boolean antiAlias = true;

    public void configBy(@Nullable PWPaintConfig other) {
        if (other == null) {
            return;
        }
        this.strokeWidth = other.strokeWidth;
        this.color = other.color;
        this.antiAlias = other.antiAlias;
    }

    public void configPaint(@NonNull Paint canvasPaint) {
        canvasPaint.setColor(color);
        canvasPaint.setStrokeWidth(strokeWidth);

        canvasPaint.setAntiAlias(antiAlias);
        //下面都是固定的
        canvasPaint.setFilterBitmap(true);
        canvasPaint.setDither(true);
        canvasPaint.setStyle(Paint.Style.STROKE);
        canvasPaint.setStrokeCap(Paint.Cap.ROUND);
        canvasPaint.setStrokeJoin(Paint.Join.ROUND);
        canvasPaint.setStrokeMiter(4.0f);
        canvasPaint.setPathEffect(null);

    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PWPaintConfig that = (PWPaintConfig) o;
        return Float.compare(that.strokeWidth, strokeWidth) == 0 && color == that.color && antiAlias == that.antiAlias;
    }

    @Override
    public int hashCode() {
        return Objects.hash(strokeWidth, color, antiAlias);
    }
}
